package com.yongcheon.sms_manager.ui.sms_spam.actionTab;

import android.app.Fragment;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.yongcheon.sms_manager.R;
import com.yongcheon.sms_manager.data.contract.ContactData;
import com.yongcheon.sms_manager.data.sms_spam.AbstractSMSData;
import com.yongcheon.sms_manager.data.sms_spam.SMSData;
import com.yongcheon.sms_manager.data.sms_spam.SpamData;
import com.yongcheon.sms_manager.database.SpamDBManager;
import com.yongcheon.sms_manager.ui.sms_spam.list.SMSCursorAdapter;
import com.yongcheon.sms_manager.ui.sms_spam.list.SPAMCurosrAdapter;

/**
 * Created by yongcheon on 2014-11-18.
 */
public class ActionTabSMSFragment extends Fragment {
    AbstractSMSData smsData;
    ContactData contactData;

    public void setSMSService(AbstractSMSData smsData){
        this.smsData = smsData;
    }
    public void setContactData(ContactData contactData){
        this.contactData = contactData;
    }

    public static ActionTabSMSFragment newInstance(String texta) {
        ActionTabSMSFragment frag = new ActionTabSMSFragment();
        Bundle args = new Bundle();
        args.putString("TAB_NAME", texta);
        frag.setArguments(args);
        return frag;
    }


    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        Bundle args = getArguments();
        String tabName = args.getString("TAB_NAME");

        View linear = inflater.inflate(R.layout.actiontabfragment, container, false);
        ListView smsList = (ListView)linear.findViewById(R.id.list);
        SQLiteDatabase database = SpamDBManager.getDatabase(container.getContext());
        if(smsData instanceof SMSData){
            SMSCursorAdapter adapter = (SMSCursorAdapter)smsData.getCurosrAdapter(container.getContext(), database);
            adapter.setSMSService(smsData);
            adapter.setContactData(contactData);
            smsList.setAdapter(adapter);
        }else if(smsData instanceof SpamData){
            SPAMCurosrAdapter adapter = (SPAMCurosrAdapter)smsData.getCurosrAdapter(container.getContext(), database);
            adapter.setSMSService(smsData);
            adapter.setContactData(contactData);
            smsList.setAdapter(adapter);
        }


        return linear;
    }

    public void setCursorAdapter(){

    }

}
